package com.ruoyi.common.utils;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;

import java.util.List;

public class SceneUtil {

    /**
     * 通过情景 获取数据 起止时间
     * @param scene
     * @return
     */
    public static List<DateTime> deal(String scene) {
        DateTime obsStart = null;
        DateTime obsEnd = null;
        if (scene.contains("~")) {
            //2014-04-22~2014-04-29:6
            String[] split = scene.split("~|:");
            String startTimeStr = split[0];
            String endTimeStr = split[1];
            //观测时间
            obsStart = DateUtil.parse(startTimeStr, "yyyy-MM-dd");
            obsEnd = DateUtil.parse(endTimeStr, "yyyy-MM-dd");
        } else {
            //单日子  2023-01-01:12
            String[] split = scene.split("~|:");
            String startTimeStr = split[0];
            obsStart = DateUtil.parse(startTimeStr, "yyyy-MM-dd");
            obsEnd = DateUtil.endOfDay(obsStart);
        }
        return ListUtil.of(obsStart,obsEnd);
    }
}
